package com.snail.controller;

import com.snail.model.vo.cart.CartItemGroupBySellerVO;
import com.snail.result.Result;
import com.snail.service.BizCartItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/cartItem")
public class BizCartItemController {

    @Autowired
    private BizCartItemService bizCartItemService;
    //删除购物车中的商品项
    @DeleteMapping("/deleteByCartIdAndProductId")
    public void deleteByCartIdAndProductId(Integer cartId, Integer productId) {
        bizCartItemService.deleteByCartIdAndProductId(cartId, productId);
    }
    //清空购物车
    @DeleteMapping("/deleteByCartId")
    public void deleteByCartId(Integer cartId) {
        bizCartItemService.deleteByCartId(cartId);
    }


    //查询用户购物车商品并按商家分组
    @GetMapping("/listCartItemGroupBySeller")
    public Result listCartItemGroupBySeller( Long userId) {
        List<CartItemGroupBySellerVO> cartItemGroupBySellerVOS = bizCartItemService.listCartItemGroupBySeller(userId);
        System.out.println("car is done");
        System.out.println(userId);
        return Result.success(cartItemGroupBySellerVOS);
    }
}
